#ifndef LANGUAGEMODEL_H
#define LANGUAGEMODEL_H

#include <baza/jezik.h>
#include <QObject>
#include <QAbstractListModel>
#include <languageitem.h>
#include <QDebug>

class LanguageModel: public QAbstractListModel
{
    Q_OBJECT

    Q_PROPERTY(int count READ count NOTIFY countChanged)

public:
    enum LanguageRoles  {
        RoleLanguageName = Qt::DisplayRole,
        RoleId = Qt::UserRole,
        RoleChosen = Qt::UserRole+1
    };

    LanguageModel(QObject *parent = 0);

    void addLanguage(const Jezik &jezik);
    void clear();

    int rowCount(const QModelIndex & parent = QModelIndex()) const;
    int count();

    Q_INVOKABLE LanguageItem* get(int index);
    QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;

    QModelIndex indexFromItem(const LanguageItem *item) const;

private slots:
    void handleItemChange();

signals:
    void countChanged(int newCount);

private:
    QList<LanguageItem*> m_languageItems;
};

#endif // LANGUAGEMODEL_H
